<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/moneryManage/BaseInfo.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
</script>

<script type="text/html" id="chaoZuoButton">
    <i class="layui-icon layui-icon-edit" style="cursor:pointer" lay-event="edit"></i>  
    <i class="layui-icon layui-icon-delete" style="cursor:pointer;padding-left: 10px;" lay-event="delete"></i>
</script>
<style scoped>
    .PeronseButton button:nth-child(1){
        width: 60px;
      font-size: 11px;
      margin: 0;
      padding: 0 5px;
      border: 0;
      text-align: center;
      background-color: #FF4C4C;
      line-height: 22px;
      height: 22px;
      vertical-align: middle;
    }
</style>
<!-- 自定义按钮 -->
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 header">
            <span class="layui-title-screen">
                <div class="screen-btn">
                    <form class="layui-form" action="">
                        <input type="search" name="keyword"
                            class="inputQuery search-blank-inner searchInput"
                            placeholder="自定义搜索" style="left: 0;top: -7px;" autocomplete="off" />
                        <button type="button" lay-submit lay-filter="query"
                            class="search search-blank-icon"></button>
                    </form>
                </div>
            </span>
        </div>
    </div>
</div>
<!-- 数据展示 -->
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 PoserTable">
            <table id="basicInformation" lay-even lay-skin="nob" class="layui-table" lay-filter="basicInformation">

            </table>
        </div>
    </div>
</div>

<!-- 按钮组合 -->
<div class="layui-fluid">
    <div class="layui-row">
        <div class="PeronseButton layui-col-xs12 layui-col-sm12 layui-col-md12">
            <button class="layui-btn layui-btn-radius layui-btn-primary del" data-type="deleteMore">
                <i class="layui-icon layui-icon-delete" style="font-size: 14px; vertical-align: top;"></i>
                <span data-lang="delete">删除</span>
            </button>
            <button class="staffInput layui-btn layui-btn-radius layui-btn-primary" data-type="addproduct">
                <i class="layui-icon layui-icon-add-circle" style="font-size: 14px; vertical-align:middle;"></i>
                <span data-lang="EmployeeEntry">员工录入</span>
            </button>
        </div>
    </div>
</div>
<!-- 弹出层 -->
<script type="text/javascript">
    layui.use(['admin', 'form', 'user', 'table', 'api', 'laytpl', 'utill', 'laydate', 'layer'], function () { //此段代码必不可少
        var $ = layui.$,
            admin = layui.admin,
            view = layui.view,
            api = layui.api,
            table = layui.table,
            setter = layui.setter,
            laytpl = layui.laytpl,
            utill = layui.utill,
            laydate = layui.laydate,
            layer = layui.layer,
            form = layui.form;

        var _TPL = {
            tcHrStatus: function (d) {
                if (d.tcHrStatus == 'N') {
                    return "<span>不允许登录</span>";
                } else if (d.tcHrStatus == 0) {
                    return "<span>未登录过</span>";
                } else if (d.tcHrStatus == 1) {
                    return "<span>正常</span>";
                } else if (d.tcHrStatus == 2) {
                    return "<span>账号锁定</span>";
                } else if (d.tcHrStatus == undefined) {
                    return "<span></span>";
                }
            }
        };
        $('.search-blank-inner').focus(function () {
        $('.searchInput').css('width', '100px')
        });
        $('.search-blank-inner').blur(function () {
            $('.searchInput').css('width', '65px')
        });
        // utill.keyup('.searchInput','.search-blank-icon');
            //列定制
        utill.columnCustom('#basicInformation', "GenExVO", {
            url: api.host + api.selectStaffList,
            where: {
                keyword: ""
            },
            toolbar: {
                toolbar: '#chaoZuoButton',
                title: '操作',
                event: 'detail',
                align: 'center'
            },
            templet: _TPL
        });
        utill.showAndHide('.staffInput,.del','TcEamGenExController:addGenEx')
        rander();   //调用方法
        function rander() {
            table.on('tool(basicInformation)', function (obj) {
                var data = obj.data
                if (obj.event === 'edit') {
                    admin.popup({
                        title: '编辑',
                        area: ['500px', '680px'],
                        id: 'LAY-popup-user-add',
                        success: function (layero, index) {
                            // 页面跳转
                            view(this.id).render('moneyManage/alert/popleEdit_alert', data).done(function () {
                                // 账户状态回显
                                var status = data.tcHrStatus;
                                if (status == 2) {
                                    $("#ones").prop("checked", true);
                                } else {
                                    $("#twos").prop("checked", true);
                                }
                                // 再一次渲染表格
                                form.render();
                                form.render(null, 'layuiadmin-form-tags');   // 渲染当期那的表格
                                // 回显效果
                                form.val("layuiadmin-form-tags", {
                                    "tcHrGen01": data.tcHrGen01,
                                    "gen02": data.gen02,
                                    "gem02": data.gem02,
                                    "azp02": data.azp02,
                                    "tcHrJob": data.tcHrJob,
                                    "gen08": data.gen08,
                                    "gen06": data.gen06,
                                })
                             
                                //监听保养项目修改
                                form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                    // 把数据传递到后台
                                    var arr = new Array();
                                    var field = data.field; //获取提交的字段
                                    arr.push(field);
                                    admin.req({
                                        url: api.host + api.setStaff,
                                        type: 'post',
                                        contentType: 'application/json',
                                        dataType: 'json',
                                        data: JSON.stringify(arr),
                                        done: function (res) {
                                            layui.table.reload('#basicInformation'); //重载表格  
                                            layer.close(index); //执行关闭    
                                            layer.msg(res.message);
                                        }
                                    });
                                });
                                // 取消按钮
                                $(".ButtonBtn").on("click", ".btn2", function () {
                                    layer.close(index);
                                });
                            });
                        }
                    });
                }
                // 单条删除(必须传人员工号)
                else if (obj.event === 'delete') {
                    var tcHrGen01Ons = obj.data.tcHrGen01;
                    var obj = {
                        hrgen01: tcHrGen01Ons
                    }
                    layer.confirm('真的删除吗？', function (index) {
                        admin.req({
                            url: api.host + api.delete_llp,
                            type: 'post',
                            data: obj,
                            //向服务端发送删除的id
                            done: function (res) {
                                layui.table.reload('#basicInformation'); //重载表格  
                                layer.close(index); //执行关闭
                                layer.msg(res.message);
                            }
                        })
                    })
                }
            });
        }


        //事件
        var active = {
            // 员工录入弹出层
            addproduct: function () {
                admin.popup({
                    title: '员工录入',
                    area: ['392px', '425px'],
                    shadeClose: true,
                    id: 'LAY-popup-user-add',
                    success: function (layers, index) {
                        view(this.id).render('moneyManage/alert/InputPoser').done(function () {
                            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                var field = data.field; //获取提交的字段
                                var fieldOne = JSON.stringify(field);
                                view.req({
                                    url: api.host + api.addGenEx,
                                    data: fieldOne,
                                    type: "POST",
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    done: function (res) {
                                        layui.table.reload('#basicInformation'); //重载表格 
                                        layer.close(index); //执行关闭 
                                        layer.msg(res.message);
                                    }
                                });
                            });
                            //监听提交
                            $(".footer").on("click", ".btn2", function () {
                                layer.close(index);
                            });
                            form.render();
                        });
                    }
                });
            },

            // 多条删除
            deleteMore: function () {
                var checkStatus = table.checkStatus('#basicInformation');
                if (checkStatus.data.length == 0) {
                    parent.layer.msg('请先选择要删除的数据行！', { icon: 2 });
                    return;
                }

                var str = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    str += checkStatus.data[i].tcHrGen01 + ","
                }
                var obj2 = {
                    hrgen01: str
                }
                admin.req({
                    type: 'post',
                    url: api.host + api.delete_llp,
                    data: obj2,
                    success: function (data) {
                        layer.msg(data.message);
                        layui.table.reload('#basicInformation'); //重载表格  
                        layer.close(index); //执行关闭   
                    }
                });
            },
        };

         form.on('submit(query)', function (data) {
            utill.columnCustom('#basicInformation', "GenExVO", {
                url: api.host + api.selectStaffList,
                where: data.field,
                toolbar: {
                    toolbar: '#chaoZuoButton',
                    title: '操作',
                    event: 'detail',
                    align: 'center'
                },
                templet: _TPL
            });
            return false;
        });
        // 回车查询
        utill.keyup('.searchInput', '.search-blank-icon');
        // 自定义搜索
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });  
    });

</script>